package erp.server.user.controller;

import erp.server.base.response.JsonResult;
import erp.server.base.response.StatusCode;
import erp.server.user.entity.dto.CreateUserDTO;
import erp.server.user.entity.dto.EditUserDTO;
import erp.server.user.entity.dto.LoginDTO;
import erp.server.user.entity.vo.MemberVO;
import erp.server.user.entity.vo.UserVO;
import erp.server.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/isms/user/")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("register")
    public JsonResult createUser(CreateUserDTO dto){
        log.debug("创建用户-入参:{}",dto);
        userService.createUser(dto);
        return new JsonResult(1010,"注册成功");
    }

    @PostMapping("login")
    public JsonResult login(LoginDTO dto){
        UserVO userVO = userService.login(dto);
        return new JsonResult(StatusCode.LOGIN_SUCCESS,userVO);
    }

    @GetMapping("select/member/{organizationID}")
    public JsonResult selectMember(@PathVariable Long organizationID){
        List<MemberVO> memberList = userService.selectMember(organizationID);
        return new JsonResult(StatusCode.OPERATION_SUCCESS,memberList);
    }

    @PostMapping("edit")
    public JsonResult editUserInfo(EditUserDTO editUserDTO){
        userService.editUserInfo(editUserDTO);
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }
}
